package aerys.minko.scene.stardust
{
	import aerys.minko.render.Scene3DVisitor;
	import aerys.minko.scene.AbstractScene3D;
	import aerys.minko.scene.IObject3D;
	import aerys.minko.scene.IScene3D;
	import aerys.minko.type.math.Matrix4x4;
	
	import flash.geom.Orientation3D;
	import flash.geom.Vector3D;
	
	import idv.cjcat.stardust.threeD.particles.Particle3D;
	
	public class ParticleObject3D extends AbstractScene3D
	{
		private static var _id	: uint				= 0;
		
		private var _particle	: Particle3D		= null;
		private var _target		: IScene3D			= null;
		
		private var _transform	: Matrix4x4			= new Matrix4x4();
		
		public function get particle() 	: Particle3D	{ return _particle; }
		public function get target()	: IScene3D		{ return _target; }
		
		override public function get version() : uint
		{
			return super.version + _transform.version + _target.version;
		}
		
		public function set particle(value : Particle3D) : void
		{
			if (value != _particle)
			{
				++_version;
				_particle = value;
			}
		}
		
		public function set target(value : IScene3D) : void
		{
			if (value != _target)
			{
				++_version;
				_target = value;
			}
		}
		
		public function ParticleObject3D(particle 	: Particle3D,
										 target		: IScene3D)
		{
			super();
			
			_particle = particle;
			_target = target;
			
			name = "ParticleObject3D_" + ++_id;
		}
		
		override public function visited(visitor : Scene3DVisitor) : void
		{
			super.visited(visitor);
			
			_transform.translation.set(_particle.x,
									   _particle.y,
									   _particle.z);
			_transform.rotation.set(_particle.rotationX,
									_particle.rotationY,
									_particle.rotationZ);
			_transform.scale.set(_particle.scale,
								 _particle.scale,
								 _particle.scale);
			
			visitor.transform.push(_transform);
			visitor.updateAndVisit(_target);
			visitor.transform.pop();
		}
	}
}